import ajax from "./ajax";

// 获取管理员列表
export function fetchAdminList() {
  return ajax.get("/api/sys/users");
}

// 新增管理员
export function newAdmin(admin) {
  return ajax.post("/api/sys/user", {
    name: admin.name,
    password: admin.password,
    phone: admin.loginName
  });
}

// 更改管理员状态
export function updateStatus(adminId, status) {
  let url = `/api/sys/user/${adminId}/status`;
  return ajax.put(url, { status: status });
}

// 重置管理员密码
export function resetAdminPwd(id, pwd) {
  let url = `/api/sys/user/${id}/password`;
  return ajax.put(url, { password: pwd });
}

// 修改管理员密码
export function updatePassword(updateObj) {
  return ajax.put("/api/sys/user/password", updateObj);
}

// 获取管理员绩效
export function getAdminPerformance(searchObj) {
  // let url = ``
  // return ajax.get(url)
  return Promise.resolve({
    data: {
      status: 200,
      data: {
        paging: true,
        pageNum: 1,
        limit: 5,
        pageCount: 1,
        total: 5,
        lastPage: true,
        orderBy: "create_time desc",
        totalData: null,
        results: [
          {
            id: 36,
            status: "QUOTATION",
            statusDesc: "待报价",
            price: 0.0,
            prodId: 1,
            prodName: "公司注册",
            prodImageUri:
              "http://47.96.11.208/upload/img/product/3f4ca5fa-fa28-4e0a-948f-e7552cb16bb9.png",
            createTime: "2019-01-24 15:40:10",
            empId: null,
            empName: null,
            customerId: 16,
            customerName: "王伟",
            location: "四川省-成都市-锦江区"
          },
          {
            id: 35,
            status: "QUOTATION",
            statusDesc: "待报价",
            price: 0.0,
            prodId: 1,
            prodName: "公司注册",
            prodImageUri:
              "http://47.96.11.208/upload/img/product/3f4ca5fa-fa28-4e0a-948f-e7552cb16bb9.png",
            createTime: "2019-01-23 12:04:22",
            empId: null,
            empName: null,
            customerId: 16,
            customerName: "王伟",
            location: "四川省-成都市-锦江区"
          },
          {
            id: 34,
            status: "QUOTATION",
            statusDesc: "待报价",
            price: 0.0,
            prodId: 1,
            prodName: "公司注册",
            prodImageUri:
              "http://47.96.11.208/upload/img/product/3f4ca5fa-fa28-4e0a-948f-e7552cb16bb9.png",
            createTime: "2019-01-23 12:03:13",
            empId: null,
            empName: null,
            customerId: 16,
            customerName: "王伟",
            location: "四川省-成都市-锦江区"
          },
          {
            id: 33,
            status: "QUOTATION",
            statusDesc: "待报价",
            price: 0.0,
            prodId: 1,
            prodName: "公司注册",
            prodImageUri:
              "http://47.96.11.208/upload/img/product/3f4ca5fa-fa28-4e0a-948f-e7552cb16bb9.png",
            createTime: "2019-01-23 12:02:05",
            empId: null,
            empName: null,
            customerId: 16,
            customerName: "王伟",
            location: "四川省-成都市-青羊区"
          },
          {
            id: 17,
            status: "QUOTATION",
            statusDesc: "待报价",
            price: 0.0,
            prodId: 4,
            prodName: "一般纳税人记账(3个月试用版)",
            prodImageUri:
              "http://47.96.11.208/upload/img/product/924c29fe-5cef-406b-a6c4-e7e1639fe06b.png",
            createTime: "2019-01-22 17:40:42",
            empId: null,
            empName: null,
            customerId: 16,
            customerName: "王伟",
            location: "四川省-成都市-锦江区"
          }
        ]
      }
    }
  });
}

/*****************角色权限相关接口*************************/
// 创建系统角色
export function newSysRole(name, description) {
  let url = `/api/permission/role`;
  return ajax.post(url, { name, description });
}
// 获取系统角色列表
export function getSysRoleList() {
  let url = "/api/permission/roles";
  return ajax.get(url);
}
// 更改角色权限
export function updateRole(roleId, permissions) {
  let url = `/api/permission/role/${roleId}/permissions?permissions=${permissions}`;
  return ajax.put(url);
}
//删除用户关联的角色
export function deleteUserRole(roleId, userId) {
  let url = `/api/permission/role/${roleId}/assign/${userId}`;
  return ajax.delete(url);
}
//分配角色给用户
export function assignUserRole(userId, roleIds) {
  let url = `/api/permission/role/assign/${userId}`;
  return ajax.post(url, { roleIds });
}
//删除角色
export function deleteRole(roleId) {
  let url = `/api/permission/role/${roleId}`;
  return ajax.delete(url);
}
//获取权限列表
export function getPermissionList() {
  let url = `/api/permission/permissions`;
  return ajax.get(url);
}
